package course;
import java.util.ArrayList;
import java.util.List;
public class Student {
    private int studentId;
    private String name;
    private String gender;
    private int grade;  // 年级
    private String major;  // 专业
    private List<Course> selectedCourses;  // 所选课程列表

    // 构造方法
    public Student(int studentId, String name, String gender, int grade, String major) {
        this.studentId = studentId;
        this.name = name;
        this.gender = gender;
        this.grade = grade;
        this.major = major;
        this.selectedCourses = new ArrayList<>();
    }

    // 选课方法
    public void selectCourse(Course course) {
        if (!selectedCourses.contains(course)) {
            selectedCourses.add(course);
            System.out.println("[" + grade + "年级" + major + "专业]学生" + name +
                    "成功选择了《" + course.getCourseName() + "》（学分：" + course.getCredits() + "）");
        } else {
            System.out.println("学生" + name + "已选过《" + course.getCourseName() + "》，无法重复选择");
        }
    }

    // 退课方法
    public void dropCourse(Course course) {
        if (selectedCourses.contains(course)) {
            selectedCourses.remove(course);
            System.out.println("[" + grade + "年级" + major + "专业]学生" + name +
                    "成功退选了《" + course.getCourseName() + "》");
        } else {
            System.out.println("学生" + name + "未选过《" + course.getCourseName() + "》，无法退选");
        }
    }

    // 打印课表方法
    public void printTimetable() {
        System.out.println("\n[" + grade + "年级" + major + "专业]学生" + name + "的课表：");
        if (selectedCourses.isEmpty()) {
            System.out.println("暂无选课记录");
            return;
        }

        double totalCredits = 0;
        for (Course course : selectedCourses) {
            System.out.println("课程编号：" + course.getCourseId() +
                    "，课程名称：" + course.getCourseName() +
                    "，学分：" + course.getCredits() +
                    "，时间：" + course.getTime() +
                    "，地点：" + course.getLocation() +
                    "，授课教师：" + course.getTeacher().getName() +
                    "（联系电话：" + course.getTeacher().getPhoneNumber() + "）");
            totalCredits += course.getCredits();
        }
        System.out.println("已选课程总学分：" + totalCredits);
    }

    // getter方法
    public int getStudentId() {
        return studentId;
    }

    public String getName() {
        return name;
    }

    public int getGrade() {
        return grade;
    }

    public String getMajor() {
        return major;
    }

    public List<Course> getSelectedCourses() {
        return selectedCourses;
    }
}
